-- ----------------------------
-- Table structure for lnmp_categories
-- ----------------------------
DROP TABLE IF EXISTS `lnmp_categories`;
CREATE TABLE `lnmp_categories` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '栏目名称',
  `parent_id` int(10) unsigned DEFAULT NULL COMMENT '父类目ID',
  `is_directory` tinyint(1) NOT NULL COMMENT '是否拥有子类目',
  `level` int(10) unsigned NOT NULL COMMENT '当前类目层级',
  `path` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '该类目所有父类目ID',
  `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `updated_at` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`),
  KEY `categories_parent_id_foreign` (`parent_id`),
  CONSTRAINT `categories_parent_id_foreign` FOREIGN KEY (`parent_id`) REFERENCES `lnmp_categories` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='类目表';

-- ----------------------------
-- Records of lnmp_categories
-- ----------------------------

+----+--------------+-----------+--------------+-------+------+---------------------+---------------------+
| id | name         | parent_id | is_directory | level | path | created_at          | updated_at          |
+----+--------------+-----------+--------------+-------+------+---------------------+---------------------+
| 26 | 老人机       |        24 |            0 |     1 | -24- | 2018-10-21 21:58:39 | 2018-10-21 21:58:39 |
| 27 | 对讲机       |        24 |            0 |     1 | -24- | 2018-10-21 21:58:39 | 2018-10-21 21:58:39 |
| 24 | 手机通讯     |      NULL |            1 |     0 | -    | 2018-10-21 21:58:39 | 2018-10-21 21:58:39 |
| 25 | 智能机       |        24 |            0 |     1 | -24- | 2018-10-21 21:58:39 | 2018-10-21 21:58:39 |
+----+--------------+-----------+--------------+-------+------+---------------------+---------------------+

-- ----------------------------
-- Table structure for lnmp_products
-- ----------------------------
DROP TABLE IF EXISTS `lnmp_products`;
CREATE TABLE `lnmp_products` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `type` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'normal' COMMENT '商品类型',
  `category_id` int(10) unsigned DEFAULT NULL COMMENT '类目ID',
  `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品名称',
  `long_title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品长标题',
  `description` text COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品详情',
  `image` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品封面图片文件路径',
  `on_sale` tinyint(1) NOT NULL DEFAULT '1' COMMENT '商品是否正在售卖',
  `rating` float(8,2) NOT NULL DEFAULT '5.00' COMMENT '商品平均评分',
  `sold_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '销量',
  `review_count` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '销量',
  `price` decimal(10,2) NOT NULL COMMENT 'SKU 最低价格',
  `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `updated_at` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`),
  KEY `products_category_id_foreign` (`category_id`),
  KEY `products_type_index` (`type`),
  CONSTRAINT `products_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `lnmp_categories` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=72 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='产品表';

-- ----------------------------
-- Records of lnmp_products
-- ----------------------------
+----+--------+-------------+---------------------+------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------   
| id | type   | category_id | title               | long_title                               | description  | image                        | on_sale | rating | sold_count | review_count | price   | created_at          | updated_at          |
+----+--------+-------------+---------------------+------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------- 
|  1 | normal |          25 | Apple iPhone X 256G | 2018最新款 iPhone X 256G 苹果手机           | html         | images/59e42830N9da56c41.jpg |       1 |   5.00 |          1 |            0 | 7599.00 | 2018-06-28 00:04:08 | 2018-10-26 17:44:52 |
+----+--------+-------------+---------------------+------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------

-- ----------------------------
-- Table structure for lnmp_product_properties
-- ----------------------------
DROP TABLE IF EXISTS `lnmp_product_properties`;
CREATE TABLE `lnmp_product_properties` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `product_id` int(10) unsigned NOT NULL COMMENT '商品ID',
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '属性名称',
  `value` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '属性值',
  PRIMARY KEY (`id`),
  KEY `product_properties_product_id_foreign` (`product_id`),
  CONSTRAINT `product_properties_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `lnmp_products` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='产品属性表';

-- ----------------------------
-- Records of lnmp_product_properties
-- ----------------------------
+----+------------+--------------+--------------+
| id | product_id | name         | value        |
+----+------------+--------------+--------------+
|  1 |          1 | 品牌名称     | 苹果/Apple     |
|  2 |          1 | 机身颜色     | 银色           |
|  3 |          1 | 机身颜色     | 灰色           |
|  4 |          1 | 存储容量     | 256G          |
+----+------------+--------------+--------------+

-- ----------------------------
-- Table structure for lnmp_product_skus
-- ----------------------------
DROP TABLE IF EXISTS `lnmp_product_skus`;
CREATE TABLE `lnmp_product_skus` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'SKU 名称',
  `description` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'SKU 描述',
  `price` decimal(10,2) NOT NULL COMMENT 'SKU 价格',
  `stock` int(10) unsigned NOT NULL COMMENT '库存',
  `product_id` int(10) unsigned NOT NULL COMMENT '所属商品 id	',
  `created_at` timestamp NULL DEFAULT NULL COMMENT '创建时间',
  `updated_at` timestamp NULL DEFAULT NULL COMMENT '修改时间',
  PRIMARY KEY (`id`),
  KEY `product_skus_product_id_foreign` (`product_id`),
  CONSTRAINT `product_skus_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `lnmp_products` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=209 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='产品sku表';

-- ----------------------------
-- Records of lnmp_product_skus
-- ----------------------------
BEGIN;
INSERT INTO `lnmp_product_skus` VALUES (1, '银色', 'Apple iPhone X 银色', 7599.00, 198, 1, '2018-06-28 00:04:08', '2018-06-29 12:22:14');
INSERT INTO `lnmp_product_skus` VALUES (2, '深空灰色', 'Apple iPhone X 深空灰色', 7699.00, 220, 1, '2018-06-28 00:04:08', '2018-06-29 00:27:01');
COMMIT;

-- ----------------------------
-- Table structure for lnmp_seckill_products
-- ----------------------------
DROP TABLE IF EXISTS `lnmp_seckill_products`;
CREATE TABLE `lnmp_seckill_products` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `product_id` int(10) unsigned NOT NULL COMMENT '商品ID',
  `start_at` datetime NOT NULL COMMENT '秒杀开始时间',
  `end_at` datetime NOT NULL COMMENT '秒杀结束时间',
  PRIMARY KEY (`id`),
  KEY `seckill_products_product_id_foreign` (`product_id`),
  CONSTRAINT `seckill_products_product_id_foreign` FOREIGN KEY (`product_id`) REFERENCES `lnmp_products` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='秒杀产品表';

-- ----------------------------
-- Records of lnmp_seckill_products
-- ----------------------------
+----+--------------+-----------------------------+---------+-------+------------+---------------------+---------------------+
| id | title        | description                 | price   | stock | product_id | created_at          | updated_at          |
+----+--------------+-----------------------------+---------+-------+------------+---------------------+---------------------+
|  1 | 银色         | Apple iPhone X 银色         | 7599.00 |   198 |          1 | 2018-06-28 00:04:08 | 2018-06-29 12:22:14 |
|  2 | 深空灰色      | Apple iPhone X 深空灰色      | 7699.00 |   220 |          1 | 2018-06-28 00:04:08 | 2018-06-29 00:27:01 |
+----+--------------+-----------------------------+---------+-------+------------+---------------------+---------------------+
